<%@tag import="com.wslds.base.util.SpringAppContextUtil"%>
<%@tag import="com.ii2d.j2ee.plugin.file.uploader.UploaderManager"%>
<%@ tag dynamic-attributes="dynAttr" body-content="empty" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ attribute name="fileIdAttributeName" required="true" rtexprvalue="true" %>
<%@ attribute name="fileExtAttributeName" required="true" rtexprvalue="true" %>
<script type="text/javascript">
function fileDialogComplete(){
	$('input[type=button]').hide();
	this.startUpload();
}

function uploadProgress(file, bytesLoaded, bytesTotal) {
	try {
		var target = this.customSettings.progressTarget;
		var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
		$('#' + target).progressbar({value: percent})
	} catch (ex) {}
}
function uploadSuccess(file, data, response) {
	var result = eval(data);
	console.log(file);
	$('#fileIdAttributeName').val(result[0].id);
	$('#fileExtAttributeName').val(file.type);
	$('input[type=button]').show();
}
</script>
<% 
	UploaderManager manager = (UploaderManager)SpringAppContextUtil.getBean(application, "uploaderManager");
	out.append(manager.generateButtonElement());
%>
<input type="hidden" id="fileIdAttributeName" name="instance.fileId" /> 
<input type="hidden" id="fileExtAttributeName" name="instance.ext" />
<div id="progressBar" style="height: 4px; width: 200px;"></div>